<style>
    :root {
        --primary: #4267B2;
        --primary-light: #E9EBF5;
        --secondary: #1DA1F2;
        --success: #28a745;
        --danger: #dc3545;
        --warning: #ffc107;
        --dark: #2D3436;
        --light: #F8F9FA;
        --gray: #636E72;
        --border: #DFE6E9;
        --shadow: 0 2px 10px rgba(0, 0, 0, 0.07);
        --shadow-hover: 0 5px 15px rgba(0, 0, 0, 0.1);
    }

    body {
        font-family: 'Inter', system-ui, -apple-system, sans-serif;
        background-color: #F5F7FA;
        color: var(--dark);
        line-height: 1.6;
        height: 100vh;
        overflow: hidden;
    }


    /* 聊天区域布局 */
    .chat-container {
        display: flex;
        height: calc(100vh - 57px);
        overflow: hidden;
    }

    /* 联系人列表 */
    .contacts-sidebar {
        width: 300px;
        background-color: white;
        border-right: 1px solid var(--border);
        display: flex;
        flex-direction: column;
        overflow: hidden;
        z-index: 100;
    }

    .contacts-sidebar .sidebar-header {
        padding: 1rem;
        border-bottom: 1px solid var(--border);
    }

    .contacts-sidebar .sidebar-tabs {
        display: flex;
        border-bottom: 1px solid var(--border);
    }

    .contacts-sidebar .sidebar-tab {
        flex: 1;
        text-align: center;
        padding: 0.75rem;
        cursor: pointer;
        font-weight: 500;
        transition: all 0.2s;
        border-bottom: 2px solid transparent;
    }

    .contacts-sidebar .sidebar-tab.active {
        color: var(--primary);
        border-bottom-color: var(--primary);
    }

    .contacts-sidebar .sidebar-tab:hover:not(.active) {
        background-color: var(--light);
    }

    .contacts-sidebar .contacts-list {
        flex: 1;
        overflow-y: auto;
    }

    .contacts-sidebar .contact-item {
        display: flex;
        align-items: center;
        padding: 0.75rem 1rem;
        cursor: pointer;
        transition: background-color 0.2s;
        border-bottom: 1px solid var(--border);
    }

    .contacts-sidebar .contact-item:hover {
        background-color: var(--light);
    }

    .contacts-sidebar .contact-item.active {
        background-color: var(--primary-light);
    }

    .contacts-sidebar .contact-avatar {
        width: 50px;
        height: 50px;
        border-radius: 50%;
        object-fit: cover;
        margin-right: 0.75rem;
        position: relative;
    }

    .contacts-sidebar .online-indicator {
        position: absolute;
        bottom: 0;
        right: 0;
        width: 14px;
        height: 14px;
        border-radius: 50%;
        background-color: var(--success);
        border: 2px solid white;
    }

    .contacts-sidebar .contact-info {
        flex: 1;
        overflow: hidden;
    }

    .contacts-sidebar .contact-name {
        font-weight: 600;
        margin-bottom: 0.1rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .contacts-sidebar .last-message {
        font-size: 0.85rem;
        color: var(--gray);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .contacts-sidebar .contact-meta {
        text-align: right;
        min-width: 60px;
    }

    .contacts-sidebar .message-time {
        font-size: 0.75rem;
        color: var(--gray);
        margin-bottom: 0.25rem;
    }

    .contacts-sidebar .unread-badge {
        background-color: var(--primary);
        color: white;
        border-radius: 50%;
        width: 20px;
        height: 20px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        font-size: 0.75rem;
        font-weight: 600;
    }

    /* 聊天区域 */
    .chat-area {
        flex: 1;
        display: flex;
        flex-direction: column;
        background-color: #f0f2f5;
        overflow: hidden;
    }

    .chat-area .chat-header {
        background-color: white;
        padding: 0.75rem 1.25rem;
        display: flex;
        align-items: center;
        justify-content: space-between;
        border-bottom: 1px solid var(--border);
    }

    .chat-area .chat-partner {
        display: flex;
        align-items: center;
    }

    .chat-area .chat-partner-avatar {
        width: 40px;
        height: 40px;
        border-radius: 50%;
        object-fit: cover;
        margin-right: 0.75rem;
    }

    .chat-area .chat-partner-info {
        min-width: 0;
    }

    .chat-area .chat-partner-name {
        font-weight: 600;
        margin-bottom: 0;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .chat-area .chat-status {
        font-size: 0.8rem;
        color: var(--gray);
    }

    .chat-area .chat-actions {
        display: flex;
        gap: 0.75rem;
    }

    .chat-area .chat-action-btn {
        background: none;
        border: none;
        color: var(--gray);
        font-size: 1.1rem;
        cursor: pointer;
        width: 36px;
        height: 36px;
        border-radius: 50%;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        transition: all 0.2s;
    }

    .chat-area .chat-action-btn:hover {
        background-color: var(--light);
        color: var(--primary);
    }

    .chat-area .messages-container {
        flex: 1;
        padding: 1.5rem;
        overflow-y: auto;
        display: flex;
        flex-direction: column;
        gap: 1rem;
    }

    .chat-area .message {
        max-width: 70%;
        padding: 0.75rem 1rem;
        border-radius: 18px;
        position: relative;
    }

    .chat-area .message.received {
        background-color: white;
        align-self: flex-start;
        border-bottom-left-radius: 4px;
    }

    .chat-area .message.sent {
        background-color: var(--primary);
        color: white;
        align-self: flex-end;
        border-bottom-right-radius: 4px;
    }

    .chat-area .message-time {
        font-size: 0.7rem;
        margin-top: 0.25rem;
        opacity: 0.8;
        text-align: right;
    }

    .chat-area .typing-indicator {
        align-self: flex-start;
        background-color: white;
        padding: 0.5rem 1rem;
        border-radius: 18px;
        border-bottom-left-radius: 4px;
    }

    .chat-area .typing-dots {
        display: flex;
        gap: 0.25rem;
    }

    .chat-area .typing-dot {
        width: 8px;
        height: 8px;
        border-radius: 50%;
        background-color: var(--gray);
        animation: typing 1.4s infinite ease-in-out both;
    }

    .chat-area .typing-dot:nth-child(1) {
        animation-delay: -0.32s;
    }

    .chat-area .typing-dot:nth-child(2) {
        animation-delay: -0.16s;
    }

    @keyframes typing {
        0%, 80%, 100% {
            transform: scale(0);
        }
        40% {
            transform: scale(1);
        }
    }

    .chat-area .message-input-area {
        background-color: white;
        padding: 0.75rem 1.25rem;
        border-top: 1px solid var(--border);
    }

    .chat-area .message-input-container {
        display: flex;
        align-items: center;
        gap: 0.75rem;
        background-color: var(--light);
        border-radius: 24px;
        padding: 0.5rem 1rem;
    }

    .chat-area .input-actions {
        display: flex;
        gap: 0.5rem;
    }

    .chat-area .input-action-btn {
        background: none;
        border: none;
        color: var(--gray);
        font-size: 1rem;
        cursor: pointer;
        transition: color 0.2s;
    }

    .chat-area .input-action-btn:hover {
        color: var(--primary);
    }

    .chat-area .message-input {
        flex: 1;
        background: none;
        border: none;
        outline: none;
        padding: 0.5rem 0;
        font-size: 0.95rem;
    }

    .chat-area .send-btn {
        background-color: var(--primary);
        color: white;
        border: none;
        border-radius: 50%;
        width: 36px;
        height: 36px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        transition: background-color 0.2s;
    }

    .chat-area .send-btn:hover {
        background-color: #365899;
    }

    /* 资料侧边栏 */
    .profile-sidebar {
        width: 300px;
        background-color: white;
        border-left: 1px solid var(--border);
        overflow-y: auto;
        transform: translateX(100%);
        transition: transform 0.3s ease;
        position: absolute;
        right: 0;
        top: 57px;
        bottom: 0;
        z-index: 90;
    }

    .profile-sidebar.active {
        transform: translateX(0);
    }

    .profile-sidebar .profile-header {
        background-color: var(--primary-light);
        padding: 1.5rem 1rem;
        text-align: center;
    }

    .profile-sidebar .profile-avatar {
        width: 100px;
        height: 100px;
        border-radius: 50%;
        object-fit: cover;
        border: 4px solid white;
        margin: 0 auto 1rem;
    }

    .profile-sidebar .profile-name {
        font-weight: 700;
        font-size: 1.25rem;
        margin-bottom: 0.25rem;
    }

    .profile-sidebar .profile-handle {
        color: var(--gray);
        font-size: 0.9rem;
        margin-bottom: 1rem;
    }

    .profile-sidebar .profile-actions {
        display: flex;
        gap: 0.5rem;
        padding: 0 1rem;
        margin-top: -1rem;
        position: relative;
        z-index: 2;
    }

    .profile-sidebar .profile-action-btn {
        flex: 1;
        padding: 0.5rem;
        border-radius: 6px;
        font-weight: 500;
        font-size: 0.9rem;
        cursor: pointer;
        transition: all 0.2s;
        text-align: center;
    }

    .profile-sidebar .primary-btn {
        background-color: var(--primary);
        color: white;
        border: 1px solid var(--primary);
    }

    .profile-sidebar .primary-btn:hover {
        background-color: #365899;
    }

    .profile-sidebar .secondary-btn {
        background-color: white;
        color: var(--primary);
        border: 1px solid var(--primary);
    }

    .profile-sidebar .secondary-btn:hover {
        background-color: var(--primary-light);
    }

    .profile-sidebar .profile-section {
        padding: 1rem;
        border-bottom: 1px solid var(--border);
    }

    .profile-sidebar .profile-section-title {
        font-size: 0.85rem;
        text-transform: uppercase;
        color: var(--gray);
        margin-bottom: 0.75rem;
        font-weight: 600;
    }

    .profile-sidebar .profile-info-item {
        display: flex;
        margin-bottom: 0.75rem;
    }

    .profile-sidebar .profile-info-item:last-child {
        margin-bottom: 0;
    }

    .profile-sidebar .info-icon {
        color: var(--primary);
        margin-right: 0.75rem;
        width: 20px;
        text-align: center;
    }

    .profile-sidebar .info-text {
        flex: 1;
    }

    .profile-sidebar .profile-stats {
        display: flex;
        justify-content: space-around;
        text-align: center;
        padding: 0.5rem 0;
    }

    .profile-sidebar .profile-stat {
        flex: 1;
    }

    .profile-sidebar .stat-value {
        font-weight: 600;
        color: var(--primary);
        font-size: 1.1rem;
    }

    .profile-sidebar .stat-label {
        color: var(--gray);
        font-size: 0.8rem;
    }

    /* 管理模态框 */
    .modal-content {
        border-radius: 12px;
        border: none;
        box-shadow: var(--shadow-hover);
    }

    .modal-content .modal-header {
        border-bottom: 1px solid var(--border);
        padding: 1rem 1.25rem;
    }

    .modal-content .modal-title {
        font-weight: 600;
        font-size: 1.1rem;
    }

    .modal-content .modal-body {
        padding: 1.25rem;
    }

    .modal-content .modal-footer {
        border-top: 1px solid var(--border);
        padding: 1rem 1.25rem;
    }

    .modal-content .management-option {
        display: flex;
        align-items: center;
        padding: 0.75rem 0;
        cursor: pointer;
        border-bottom: 1px solid var(--border);
    }

    .modal-content .management-option:last-child {
        border-bottom: none;
    }

    .modal-content .management-option:hover {
        background-color: var(--light);
    }

    .modal-content .option-icon {
        color: var(--gray);
        margin-right: 0.75rem;
        width: 24px;
        text-align: center;
    }

    .modal-content .option-danger .option-icon {
        color: var(--danger);
    }

    .modal-content .option-text {
        flex: 1;
        font-weight: 500;
    }

    /* 群聊特有样式 */
    .group-members {
        display: flex;
        flex-wrap: wrap;
        gap: 0.5rem;
        padding: 0.5rem 0;
    }

    .group-member {
        width: 36px;
        height: 36px;
        border-radius: 50%;
        object-fit: cover;
        border: 2px solid white;
    }

    .group-member.more {
        background-color: var(--primary-light);
        color: var(--primary);
        display: flex;
        align-items: center;
        justify-content: center;
        font-weight: 600;
        font-size: 0.8rem;
    }

    /* 响应式设计 */
    @media (max-width: 992px) {
        .contacts-sidebar {
            width: 100%;
            position: absolute;
            left: 0;
            top: 57px;
            bottom: 0;
            transform: translateX(-100%);
            transition: transform 0.3s ease;
        }

        .contacts-sidebar.active {
            transform: translateX(0);
        }

        .chat-area {
            width: 100%;
        }

        .chat-container .mobile-back-btn {
            display: block !important;
        }
    }

    .chat-container .mobile-back-btn {
        display: none;
        background: none;
        border: none;
        color: var(--gray);
        font-size: 1.1rem;
        margin-right: 0.5rem;
    }
</style>


<!-- 聊天容器 -->
<div class="chat-container">
    <!-- 联系人/群组列表侧边栏 -->
    <div class="contacts-sidebar active">
        <div class="sidebar-header">
            <div class="search-bar">
                <i class="fas fa-search search-icon"></i>
                <input type="text" class="search-input" placeholder="搜索聊天、联系人或群组...">
            </div>
        </div>

        <div class="sidebar-tabs">
            <div class="sidebar-tab active">私聊</div>
            <div class="sidebar-tab">群聊</div>
        </div>

        <div class="contacts-list">
            <!-- 私聊联系人 -->
            <div class="contact-item active" data-type="user" data-id="1">
                <div class="contact-avatar">
                    <img src="https://picsum.photos/100/100?random=2" alt="李华头像" class="w-100 h-100 rounded-circle">
                    <span class="online-indicator"></span>
                </div>
                <div class="contact-info">
                    <div class="contact-name">李华</div>
                    <div class="last-message">好的，我们明天见！</div>
                </div>
                <div class="contact-meta">
                    <div class="message-time">10:24</div>
                    <div class="unread-badge">3</div>
                </div>
            </div>

            <div class="contact-item" data-type="user" data-id="2">
                <div class="contact-avatar">
                    <img src="https://picsum.photos/100/100?random=3" alt="王芳头像" class="w-100 h-100 rounded-circle">
                    <span class="online-indicator"></span>
                </div>
                <div class="contact-info">
                    <div class="contact-name">王芳</div>
                    <div class="last-message">这个周末的活动你参加吗？</div>
                </div>
                <div class="contact-meta">
                    <div class="message-time">昨天</div>
                </div>
            </div>

            <div class="contact-item" data-type="user" data-id="3">
                <div class="contact-avatar">
                    <img src="https://picsum.photos/100/100?random=4" alt="张伟头像" class="w-100 h-100 rounded-circle">
                </div>
                <div class="contact-info">
                    <div class="contact-name">张伟</div>
                    <div class="last-message">我已经把文件发你邮箱了</div>
                </div>
                <div class="contact-meta">
                    <div class="message-time">周一</div>
                </div>
            </div>

            <!-- 群聊 -->
            <div class="contact-item" data-type="group" data-id="101">
                <div class="contact-avatar">
                    <img src="https://picsum.photos/100/100?random=10" alt="摄影爱好者群头像"
                         class="w-100 h-100 rounded-circle">
                </div>
                <div class="contact-info">
                    <div class="contact-name">摄影爱好者群</div>
                    <div class="last-message">李明：周末有外拍活动，有人参加吗？</div>
                </div>
                <div class="contact-meta">
                    <div class="message-time">09:15</div>
                    <div class="unread-badge">8</div>
                </div>
            </div>

            <div class="contact-item" data-type="group" data-id="102">
                <div class="contact-avatar">
                    <img src="https://picsum.photos/100/100?random=11" alt="前端开发技术交流群头像"
                         class="w-100 h-100 rounded-circle">
                </div>
                <div class="contact-info">
                    <div class="contact-name">前端开发技术交流群</div>
                    <div class="last-message">赵工：分享一个很好用的UI库</div>
                </div>
                <div class="contact-meta">
                    <div class="message-time">昨天</div>
                </div>
            </div>

            <div class="contact-item" data-type="group" data-id="103">
                <div class="contact-avatar">
                    <img src="https://picsum.photos/100/100?random=12" alt="大学同学群头像" class="w-100 h-100 rounded-circle">
                </div>
                <div class="contact-info">
                    <div class="contact-name">大学同学群</div>
                    <div class="last-message">班长：毕业10周年聚会时间定了</div>
                </div>
                <div class="contact-meta">
                    <div class="message-time">3天前</div>
                </div>
            </div>
        </div>
    </div>

    <!-- 聊天区域 -->
    <div class="chat-area">
        <div class="chat-header">
            <button class="mobile-back-btn">
                <i class="fas fa-arrow-left"></i>
            </button>
            <div class="chat-partner">
                <img src="https://picsum.photos/100/100?random=2" alt="李华头像" class="chat-partner-avatar">
                <div class="chat-partner-info">
                    <div class="chat-partner-name">李华</div>
                    <div class="chat-status">正在输入...</div>
                </div>
            </div>
            <div class="chat-actions">
                <button class="chat-action-btn" title="查看资料" id="view-profile-btn">
                    <i class="fas fa-user"></i>
                </button>
                <button class="chat-action-btn" title="更多选项" id="more-options-btn">
                    <i class="fas fa-ellipsis-v"></i>
                </button>
            </div>
        </div>

        <div class="messages-container">
            <div class="message received">
                嗨，最近怎么样？上次你说的那个项目进展如何了？
                <div class="message-time">09:30</div>
            </div>

            <div class="message sent">
                还不错，项目进行得很顺利，预计下个月就能完成了。
                <div class="message-time">09:45</div>
            </div>

            <div class="message received">
                太好了！完成后我们一起庆祝一下吧？
                <div class="message-time">10:02</div>
            </div>

            <div class="message sent">
                好啊，没问题！你有什么好建议吗？
                <div class="message-time">10:15</div>
            </div>

            <div class="message received">
                我知道一家新开的西餐厅很不错，我们可以去试试。
                <div class="message-time">10:24</div>
            </div>

            <div class="typing-indicator">
                <div class="typing-dots">
                    <div class="typing-dot"></div>
                    <div class="typing-dot"></div>
                    <div class="typing-dot"></div>
                </div>
            </div>
        </div>

        <div class="message-input-area">
            <div class="message-input-container">
                <div class="input-actions">
                    <button class="input-action-btn" title="表情">
                        <i class="far fa-smile"></i>
                    </button>
                    <button class="input-action-btn" title="图片">
                        <i class="far fa-image"></i>
                    </button>
                    <button class="input-action-btn" title="文件">
                        <i class="far fa-file"></i>
                    </button>
                </div>
                <input type="text" class="message-input" placeholder="输入消息...">
                <button class="send-btn">
                    <i class="fas fa-paper-plane"></i>
                </button>
            </div>
        </div>
    </div>

    <!-- 资料侧边栏 -->
    <div class="profile-sidebar" id="profile-sidebar">
        <div class="profile-header">
            <img src="https://picsum.photos/100/100?random=2" alt="李华头像" class="profile-avatar">
            <h3 class="profile-name">李华</h3>
            <p class="profile-handle">@lihua</p>
            <div class="profile-status">在线 - 正在输入</div>
        </div>

        <div class="profile-actions">
            <button class="profile-action-btn primary-btn">
                <i class="fas fa-comment"></i> 发消息
            </button>
            <button class="profile-action-btn secondary-btn">
                <i class="fas fa-phone"></i>
            </button>
        </div>

        <div class="profile-section">
            <h4 class="profile-section-title">个人简介</h4>
            <p>产品经理 | 旅行爱好者 | 咖啡控<br>
                热爱生活，喜欢探索新事物</p>
        </div>

        <div class="profile-section">
            <h4 class="profile-section-title">统计信息</h4>
            <div class="profile-stats">
                <div class="profile-stat">
                    <div class="stat-value">248</div>
                    <div class="stat-label">帖子</div>
                </div>
                <div class="profile-stat">
                    <div class="stat-value">356</div>
                    <div class="stat-label">关注</div>
                </div>
                <div class="profile-stat">
                    <div class="stat-value">1.2k</div>
                    <div class="stat-label">粉丝</div>
                </div>
            </div>
        </div>

        <div class="profile-section">
            <h4 class="profile-section-title">联系信息</h4>
            <div class="profile-info-item">
                <div class="info-icon">
                    <i class="fas fa-map-marker-alt"></i>
                </div>
                <div class="info-text">北京市朝阳区</div>
            </div>
            <div class="profile-info-item">
                <div class="info-icon">
                    <i class="fas fa-birthday-cake"></i>
                </div>
                <div class="info-text">1990年5月12日</div>
            </div>
            <div class="profile-info-item">
                <div class="info-icon">
                    <i class="fas fa-link"></i>
                </div>
                <div class="info-text">www.lihua-blog.com</div>
            </div>
        </div>

        <div class="profile-section">
            <h4 class="profile-section-title">共同群组</h4>
            <div class="profile-info-item">
                <div class="info-icon">
                    <i class="fas fa-users"></i>
                </div>
                <div class="info-text">产品经理交流群</div>
            </div>
            <div class="profile-info-item">
                <div class="info-icon">
                    <i class="fas fa-users"></i>
                </div>
                <div class="info-text">北京创业圈</div>
            </div>
        </div>
    </div>
</div>

<!-- 用户管理模态框 -->
<div class="modal fade" id="user-management-modal" tabindex="-1">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">聊天设置</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
            </div>
            <div class="modal-body">
                <div class="management-option">
                    <div class="option-icon">
                        <i class="fas fa-star"></i>
                    </div>
                    <div class="option-text">置顶聊天</div>
                </div>
                <div class="management-option">
                    <div class="option-icon">
                        <i class="fas fa-bell-slash"></i>
                    </div>
                    <div class="option-text">屏蔽消息</div>
                </div>
                <div class="management-option">
                    <div class="option-icon">
                        <i class="fas fa-history"></i>
                    </div>
                    <div class="option-text">清空聊天记录</div>
                </div>
                <div class="management-option option-danger">
                    <div class="option-icon">
                        <i class="fas fa-user-times"></i>
                    </div>
                    <div class="option-text">删除联系人</div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>
</div>

<!-- 群组管理模态框 -->
<div class="modal fade" id="group-management-modal" tabindex="-1" style="display: none;">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">群组设置</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
            </div>
            <div class="modal-body">
                <div class="management-option">
                    <div class="option-icon">
                        <i class="fas fa-star"></i>
                    </div>
                    <div class="option-text">置顶聊天</div>
                </div>
                <div class="management-option">
                    <div class="option-icon">
                        <i class="fas fa-bell-slash"></i>
                    </div>
                    <div class="option-text">屏蔽群消息</div>
                </div>
                <div class="management-option">
                    <div class="option-icon">
                        <i class="fas fa-user-plus"></i>
                    </div>
                    <div class="option-text">邀请好友加入</div>
                </div>
                <div class="management-option">
                    <div class="option-icon">
                        <i class="fas fa-users"></i>
                    </div>
                    <div class="option-text">查看群成员</div>
                </div>
                <div class="management-option">
                    <div class="option-icon">
                        <i class="fas fa-edit"></i>
                    </div>
                    <div class="option-text">编辑群组资料</div>
                </div>
                <div class="management-option option-danger">
                    <div class="option-icon">
                        <i class="fas fa-sign-out-alt"></i>
                    </div>
                    <div class="option-text">退出群组</div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>
</div>


<script>
	document.addEventListener('DOMContentLoaded', function () {
		// 元素引用
		const contactsSidebar = document.querySelector('.contacts-sidebar');
		const profileSidebar = document.getElementById('profile-sidebar');
		const viewProfileBtn = document.getElementById('view-profile-btn');
		const moreOptionsBtn = document.getElementById('more-options-btn');
		const userManagementModal = new bootstrap.Modal(document.getElementById('user-management-modal'));
		const groupManagementModal = new bootstrap.Modal(document.getElementById('group-management-modal'));
		const contactItems = document.querySelectorAll('.contact-item');
		const mobileBackBtn = document.querySelector('.mobile-back-btn');
		const sidebarTabs = document.querySelectorAll('.sidebar-tab');
		const messageInput = document.querySelector('.message-input');
		const sendBtn = document.querySelector('.send-btn');
		const messagesContainer = document.querySelector('.messages-container');

		// 当前选中的聊天类型和ID
		let currentChatType = 'user';
		let currentChatId = '1';

		// 切换联系人/群组标签
		sidebarTabs.forEach(tab => {
			tab.addEventListener('click', function () {
				sidebarTabs.forEach(t => t.classList.remove('active'));
				this.classList.add('active');

				// 在实际应用中，这里应该根据选择的标签筛选显示私聊或群聊
			});
		});

		// 选择联系人/群组
		contactItems.forEach(item => {
			item.addEventListener('click', function () {
				// 更新选中状态
				contactItems.forEach(i => i.classList.remove('active'));
				this.classList.add('active');

				// 获取聊天类型和ID
				currentChatType = this.getAttribute('data-type');
				currentChatId = this.getAttribute('data-id');

				// 在移动设备上隐藏联系人列表，显示聊天区域
				if (window.innerWidth <= 992) {
					contactsSidebar.classList.remove('active');
				}

				// 在实际应用中，这里应该加载对应聊天的历史消息
				// 这里仅做演示用
				updateChatHeader();
			});
		});

		// 移动端返回按钮
		mobileBackBtn.addEventListener('click', function () {
			contactsSidebar.classList.add('active');
		});

		// 查看资料
		viewProfileBtn.addEventListener('click', function () {
			profileSidebar.classList.add('active');
			// 在实际应用中，这里应该根据当前聊天对象加载对应的资料
		});

		// 关闭资料侧边栏
		profileSidebar.addEventListener('click', function (e) {
			if (e.target === this) {
				profileSidebar.classList.remove('active');
			}
		});

		// 更多选项
		moreOptionsBtn.addEventListener('click', function () {
			// 根据当前聊天类型显示不同的管理模态框
			if (currentChatType === 'user') {
				userManagementModal.show();
			} else {
				groupManagementModal.show();
			}
		});

		// 发送消息
		function sendMessage() {
			const messageText = messageInput.value.trim();
			if (messageText) {
				// 创建新消息元素
				const messageElement = document.createElement('div');
				messageElement.className = 'message sent';
				messageElement.innerHTML = `
                        ${messageText}
                        <div class="message-time">${new Date().getHours()}:${String(new Date().getMinutes()).padStart(2, '0')}</div>
                    `;

				// 添加到消息容器
				messagesContainer.appendChild(messageElement);

				// 清空输入框
				messageInput.value = '';

				// 滚动到底部
				messagesContainer.scrollTop = messagesContainer.scrollHeight;

				// 模拟对方回复
				setTimeout(simulateReply, 1000);
			}
		}

		// 模拟回复
		function simulateReply() {
			const replies = [
				"好的，我知道了。",
				"这个想法不错！",
				"我稍后回复你，可以吗？",
				"没问题，就这么定了。",
				"我需要再考虑一下。"
			];

			const randomReply = replies[Math.floor(Math.random() * replies.length)];

			// 创建回复消息元素
			const messageElement = document.createElement('div');
			messageElement.className = 'message received';
			messageElement.innerHTML = `
                    ${randomReply}
                    <div class="message-time">${new Date().getHours()}:${String(new Date().getMinutes()).padStart(2, '0')}</div>
                `;

			// 移除正在输入指示器（如果存在）
			const typingIndicator = document.querySelector('.typing-indicator');
			if (typingIndicator) {
				messagesContainer.removeChild(typingIndicator);
			}

			// 添加到消息容器
			messagesContainer.appendChild(messageElement);

			// 滚动到底部
			messagesContainer.scrollTop = messagesContainer.scrollHeight;
		}

		// 点击发送按钮发送消息
		sendBtn.addEventListener('click', sendMessage);

		// 按Enter键发送消息
		messageInput.addEventListener('keypress', function (e) {
			if (e.key === 'Enter') {
				sendMessage();
			}
		});

		// 更新聊天头部信息
		function updateChatHeader() {
			const chatPartnerName = document.querySelector('.chat-partner-name');
			const chatPartnerAvatar = document.querySelector('.chat-partner-avatar');
			const chatStatus = document.querySelector('.chat-status');

			// 在实际应用中，这里应该根据currentChatId加载对应的用户/群组信息
			if (currentChatType === 'user') {
				// 模拟用户信息
				const userNames = {
					'1': '李华',
					'2': '王芳',
					'3': '张伟'
				};

				const userAvatars = {
					'1': 'https://picsum.photos/100/100?random=2',
					'2': 'https://picsum.photos/100/100?random=3',
					'3': 'https://picsum.photos/100/100?random=4'
				};

				chatPartnerName.textContent = userNames[currentChatId];
				chatPartnerAvatar.src = userAvatars[currentChatId];
				chatStatus.textContent = '在线';
			} else {
				// 模拟群组信息
				const groupNames = {
					'101': '摄影爱好者群',
					'102': '前端开发技术交流群',
					'103': '大学同学群'
				};

				const groupAvatars = {
					'101': 'https://picsum.photos/100/100?random=10',
					'102': 'https://picsum.photos/100/100?random=11',
					'103': 'https://picsum.photos/100/100?random=12'
				};

				chatPartnerName.textContent = groupNames[currentChatId];
				chatPartnerAvatar.src = groupAvatars[currentChatId];

				// 群组显示成员数量
				chatStatus.textContent = '24名成员，12人在线';
			}
		}

		// 响应式调整
		window.addEventListener('resize', function () {
			if (window.innerWidth > 992) {
				contactsSidebar.classList.add('active');
			}
		});
	});
</script>

